package tv_megazineplus
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.DefaultValue
import org.codehaus.groovy.runtime.TimeCategory


@Path('/api/getProgrammsList')
class GetProgrammsListResource {
    
    @GET
    @Produces(['application/xml'])
    List<Programmation> getGetProgrammsListRepresentation(@QueryParam('channelID') String channelID) {
        def t1 = System.currentTimeMillis()
        if(channelID==null){
           return null
        }
        
        def canal = Channel2.get(channelID)
        if(canal==null){
            return null
        }
        def progs = Programmation.findAllByProg_channel(canal)
        def tt = System.currentTimeMillis() - t1
        new Statistic(servico: Servicos.findByName('getProgrammsList'), totalTime: tt, date: new Date()).save()
        return progs
    }
    
}
